package com.grf.kafka.java.interceptor;

import org.apache.kafka.clients.consumer.ConsumerInterceptor;
import org.apache.kafka.clients.consumer.ConsumerRecords;

import java.util.Map;

/**
 * @author grf
 * @apiNote
 * @since 2024/10/28
 */
public class MyConsumerInterceptor implements ConsumerInterceptor {
    @Override
    public ConsumerRecords onConsume(ConsumerRecords consumerRecords) {
        System.out.println("consumer Record : " + consumerRecords.toString());
        consumerRecords.forEach(record -> {
            System.out.println("record:"+record.toString());
        });
        return null;
    }

    @Override
    public void close() {
        System.out.println("consumer closed");
    }

    @Override
    public void onCommit(Map map) {
        System.out.println("consumer commit map:"+map.toString());
    }

    @Override
    public void configure(Map<String, ?> configs) {
        System.out.println("=====consumer config start======");
        for (Map.Entry<String, ?> entry : configs.entrySet()) {
            System.out.println("entry.key:"+entry.getKey()+" === entry.value:"+entry.getValue());
        }
        System.out.println("=====consumer config end======");
    }
}
